package com.atguigu.crowd.controller;


import atguigu.crowd.util.ResultEntity;
import com.atguigu.crowd.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class RedisController {

    @Autowired
    private RedisService redisService;

    // 设置值，不设置过期时间
    @GetMapping("/set/redis/key/value/remote")
    public ResultEntity<String> setRedisKeyValueRemote(@RequestParam("key") String key,
                                                       @RequestParam("value") String value) {
        return redisService.setRedisKeyValueRemote(key, value);
    }

    // 设置值，设置过期时间
    @GetMapping("/set/redis/key/value/remote/timeout")
    public ResultEntity<String> setRedisKeyValueRemoteWithTimeOut(@RequestParam("key") String key,
                                                                  @RequestParam("value") String value,
                                                                  @RequestParam("time") Long time) {
        return redisService.setRedisKeyValueRemoteWithTimeOut(key, value, time);
    }

    // 得到键值
    @RequestMapping("/get/redis/string/value/by/key")
    public ResultEntity<String> getRedisStringValueByKeyRemote(@RequestParam("key") String key) {
        return redisService.getRedisStringValueByKeyRemote(key);
    }

    // 删除键
    @GetMapping("/remote/redis/key/remote")
    public ResultEntity<String> removeRedisKeyRemote(@RequestParam("key") String key) {
        return redisService.removeRedisKeyRemote(key);
    }

}
